/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Ownership")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ownership.findAll", query = "SELECT o FROM Ownership o"),
    @NamedQuery(name = "Ownership.findByPlayer", query = "SELECT o FROM Ownership o WHERE o.ownershipPK.player = :player"),
    @NamedQuery(name = "Ownership.findByUnit", query = "SELECT o FROM Ownership o WHERE o.ownershipPK.unit = :unit"),
    @NamedQuery(name = "Ownership.findByAmount", query = "SELECT o FROM Ownership o WHERE o.amount = :amount")})
public class Ownership implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected OwnershipPK ownershipPK;
    @Column(name = "amount")
    private Integer amount;
    @JoinColumn(name = "unit", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Unit unit1;
    @JoinColumn(name = "player", referencedColumnName = "username", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Player player1;

    public Ownership() {
    }

    public Ownership(OwnershipPK ownershipPK) {
        this.ownershipPK = ownershipPK;
    }

    public Ownership(String player, int unit) {
        this.ownershipPK = new OwnershipPK(player, unit);
    }

    public OwnershipPK getOwnershipPK() {
        return ownershipPK;
    }

    public void setOwnershipPK(OwnershipPK ownershipPK) {
        this.ownershipPK = ownershipPK;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Unit getUnit1() {
        return unit1;
    }

    public void setUnit1(Unit unit1) {
        this.unit1 = unit1;
    }

    public Player getPlayer1() {
        return player1;
    }

    public void setPlayer1(Player player1) {
        this.player1 = player1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ownershipPK != null ? ownershipPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ownership)) {
            return false;
        }
        Ownership other = (Ownership) object;
        if ((this.ownershipPK == null && other.ownershipPK != null) || (this.ownershipPK != null && !this.ownershipPK.equals(other.ownershipPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Ownership[ ownershipPK=" + ownershipPK + " ]";
    }
    
}
